#include <string>
#include <iostream>
using namespace std;

class Stack {
    struct Node {
        int val;
        Node* next;
        Node() : val{}, next{nullptr} {}
        Node(int _val) : val{_val}, next{nullptr} {}
        Node(int _val, Node* _next) : val{_val}, next{_next} {}
    };

    Node* dummy = new Node();
public:
    Stack() {}
    ~Stack() {
        for (Node* cur = dummy, * nxt; cur; cur = nxt) {
            nxt = cur->next;
            delete cur;
        }
    }

    bool empty() {
        return not dummy->next;
    }

    void push(int val) {
        Node* node = new Node(val, dummy->next);
        dummy->next = node;
    }

    bool pop() {
        if (empty()) {
            return false;
        }
        Node* node = dummy->next;
        dummy->next = node->next;
        delete node;
        return true;
    }

    int top() {
        if (empty()) {
            perror("empty!");
            return 0x3f3f3f3f;
        }
        return dummy->next->val;
    }

};

int main() {
   Stack st;
   st.push(1);
   st.push(2);
   st.push(5);
   st.push(7);
   st.push(9);
   st.push(11);
   st.push(13);
   cout << st.top() << endl;
   st.pop();
   cout << st.top() << endl;
   st.pop();
   cout << st.top() << endl;
   st.pop();
   cout << st.top() << endl;
   st.pop();
   cout << st.top() << endl;
   st.pop();
   cout << st.top() << endl;
   st.pop();
   cout << st.top() << endl;
   st.pop();
   cout << st.top() << endl;
   st.pop();
   cout << st.top() << endl;
   st.pop();

}